#include <iostream>

using namespace std;
const int N=100,ROW=20,COLUMN=5;
int is_purchased[ROW][COLUMN]= {0};
int ticket_num[N]= {0};
int main_47()
{
    int n,ticket,remain,start,stop,is_adjacent;
    cin>>n;
    for (int i=0; i<n ; i++ )
    {
        cin>>ticket_num[i];
    }
    for (int i=0; i<n ; i++ )
    {
        ticket=ticket_num[i];
        for (int j=0; j<ROW ; j++ )
        {
            remain=5,is_adjacent=0;
            for (int l=0; l<COLUMN ; l++ )
            {
                remain-=is_purchased[j][l];
            }
            if (remain>=ticket)
            {
                start=COLUMN-remain;
                stop=start+ticket;
                for (int k=start; k<stop ; k++ )
                {
                    is_purchased[j][k]=1;
                    cout<<(5*j+k+1)<<" ";
                }
                is_adjacent=1;
                break;
            }
        }
        if (!is_adjacent)
        {
            for (int j=0;j<ROW ;j++ )
            {
                for (int k=0;(k<COLUMN)&&(ticket>0) ;k++ )
                {
                    if (!is_purchased[j][k])
                    {
                        ticket--;
                        is_purchased[j][k]=1;
                        cout << (5*j+k+1) << " ";
                    }
                }
            }
        }
        cout << endl;
    }
    return 0;
}
